using System.Collections.Generic;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;

namespace FU.Capstones.IMS.Web.Common.LoginHandlers
{
    public static class AccountPublisher
    {
        private static readonly object LockObj = new object();
        private static readonly List<ISubcriber> SubcriberCollection = new List<ISubcriber>();

        public static void AddSubcriber(ISubcriber accountSubcriber)
        {
            lock (LockObj)
            {
                if (!(SubcriberCollection.Contains(accountSubcriber)))
                    SubcriberCollection.Add(accountSubcriber);
            }
        }

        public static void NotifyAccountChanged(Account account)
        {
            SubcriberCollection.ForEach(accountSubcriber => accountSubcriber.AccountChanged(account));
        }
    }
}